package com.hotacorp.opencloud.authserver.handler;

import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

/**
 * 应用事件监听，用户登录成功监听
 * @author lwg
 *
 */
@Component
@Slf4j
public class AuthenticationSuccessEvenHandler implements ApplicationListener<AuthenticationSuccessEvent> {

	@Override
	public void onApplicationEvent(AuthenticationSuccessEvent event) {
		Authentication authentication = (Authentication) event.getSource();
		if (authentication.getAuthorities() != null && !authentication.getAuthorities().isEmpty())
			log.info("用户：{} 登录成功", authentication.getPrincipal());

	}
}